<?php

namespace App\Http\Controllers\NewAdmin;

use App\Http\Controllers\AdapterWebController;
use Illuminate\Http\Request;

class Setting extends AdapterWebController
{
    /**
     * 获取配置列表
     */
    public function getSettingList(Request $request)
    {
        $postData = $request->except('_token');
        $list = $this->appLayerExec(\App\Modules\Setting\Setting::class, 'getSettingList', $postData, false);
        return view('NewAdmin.Setting.setting_list', ['list' => $list]);
    }

    /**
     * 编辑配置
     * @param Request $request
     * @param $id
     * @return array|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
     * @throws \App\Exceptions\RequestFailException
     */
    public function editSetting(Request $request, $id)
    {
        $postData = $request->except('_token');
        $postData['id'] = $id;
        if ($request->isMethod('get')) {
            $info = $this->appLayerExec(\App\Modules\Setting\Setting::class, 'getOneSet', $postData, false);
            return view('NewAdmin.setting.edit_setting_page', ['info' => $info['res']]);
        }

        if ($request->isMethod('post')) {
            $res = $this->appLayerExec(\App\Modules\Setting\Setting::class, 'editSetting', $postData, false);
            return $res['status'] == SUCCESS_STATUS ?
                ['status' => 0, 'msg' => '编辑成功'] :
                ['status' => -1, 'msg' => $res['res']['autoRes']];
        }

        return ['status' => -1, 'msg' => '编辑失败'];
    }
}
